<template>
  <li id="tabbaritems" @click="toggle">
    <template>
      <slot name="normal" v-if="!isactive"> </slot>
    </template>

    <template>
      <slot name="active" v-if="isactive"> </slot>
    </template>
    <p class="title" :style="activeStyle">{{ title }}</p>
  </li>
</template>
<script>
export default {
  // 父传子
  // props: ["title", "mark", "currimg"],
  props: {
    title: String,
    mark: String,
    currimg: String,
  },
  computed: {
    isactive() {
      // 判断要显示活跃还是不活跃的图片
      if (this.$route.path === "/" && this.mark == this.currimg) {
        return true;
      } else if (this.$route.path.includes(this.mark)) {
        return true;
      } else {
        return false;
      }
    },
    activeStyle() {
      return this.isactive ? { color: "#FF384FFF" } : {};
    },
  },
  methods: {
    toggle() {
      // 子传父 更新currimg
      this.$emit("change", this.mark);
      // 路由跳转
      this.$router.push("/" + this.mark).catch((err) => {});
    },
  },
};
</script>

<style lang="less" scoped>
#tabbaritems {
  flex: 1;
  height: 97px;
  font-size: 0;
  .title {
    font-size: 20px;
    color: #333333;
    margin-top: 6px;
  }
  img {
    height: 40px;
    margin-top: 9px;
    width: 40px;
  }
}
</style>